<?php

$deId = $_GET['pid'] > 0 ? $_GET['pid'] : $_POST['deId'];

if ($deId < 1 || $deId == '') {

    header('Location: newsletter_list.php');
    exit;
}

include_once('../controller/includes/db_access.php');

if ((isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : '')) == 'multiple') {

    $first_name =  stripslashes($_POST['vn']);
    $last_name  =  stripslashes($_POST['an']);
    $compagny   =  stripslashes($_POST['compagny']);
    $email      =  stripslashes($_POST['email']);
    $aktief     = stripslashes($_POST['aktief']);
    $newsletter_id = $_POST['deId'];
    
    $q = new Query;
    $q
            ->update('`newsletter`')
            ->set(
                    array(
                       '`first_name`' => $first_name,
                       '`last_name`' => $last_name,
                       '`compagny`' => $compagny,
                       '`email`' => $email,
                       '`aktief`' => $aktief,
                      )
            )
            ->from('`newsletter`')
            ->where_equal_to(
                    array(
                        '`newsletter`.`newsletter_id`' => $newsletter_id
                    )
            )
            ->limit(1);
    
$result = $q->run();

if (!($result && $q->get_affected() > 0)) {
        
        $Error = 'No category found.' . "\n";
        
    } else 
        {

           header('Location: newsletter_list.php');  
           
        }

}
?>
<?php
if(isset($_GET['pid'])){

$id = $_GET['pid'];
$q = new Query;
$q
        ->select('*'
        )
        ->from('`newsletter`')
        ->where_equal_to(
                array(
                    '`newsletter`.`newsletter_id`' => $id,
                )
);

$result = $q->run();

if (!($result > 0)) {
    $Error = 'No category found.' . "\n";
} else {
    $rows = mysql_fetch_object($result);
}

}
?>
<html>
<head>
<meta charset="utf-8" />
<!--[if lt IE 9]>
<script
src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="stylesheet" href="styles/style.css" type="text/css" />
<!--[if lte IE 7]>
<link rel="stylesheet" href="style_ie.css" />
<![endif]-->
<title>dbme!!!!</title>
</head>
<body>
<div id="bloc_page">
<header>

</header>  
 <nav>
    <?php include_once('header.php'); ?>
</nav>
 <section>

    <article>
         <form name="form1" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
           <input type="hidden" name="action" value="multiple" />  
           <input type="hidden" name="deId" value="<?php echo $deId; ?>" /> 
          <table>
                <tr>
                 <td colspan="2" class="title" style="width: 100%;">Mail list edit</td>
                </tr>
                  <tr valign="baseline">
                    <td  width="20px">Voornaam:</td>
                    <td valign="baseline"> <input name="vn" type="text" maxlength="50" value="<?php echo $rows->first_name; ?>" /></td>
                </tr>
                 <tr valign="baseline">
                    <td >Achternaam:</td>
                    <td valign="baseline"> <input name="an" type="text" maxlength="50" value="<?php echo $rows->last_name; ?>" /></td>
                </tr>
                 <tr valign="baseline">
                    <td >Bedrijf:</td>
                    <td valign="baseline"> <input name="compagny" type="text" maxlength="50" value="<?php echo $rows->compagny; ?>" /></td>
                </tr>
                 <tr valign="baseline">
                    <td >Email:</td>
                    <td valign="baseline"> <input name="email" type="email" value="<?php echo $rows->email; ?>" /></td>
                </tr>
               <tr valign="baseline">
                    <td align="left" nowrap="nowrap" bgcolor="#CCCCCC">Aktief:</td>
                    <td valign="baseline" bgcolor="#EFEFEF">
                    Ja <input name="aktief" type="radio" value="Y" <?php if( trim($rows->aktief)== 'Y') echo ' checked';?> /> 
                    Nee <input name="aktief" type="radio" value="N" <?php if( trim($rows->aktief)!= 'Y') echo ' checked';?> />
                    </td>
                </tr>
               <tr valign="baseline">
                    <td ></td>
                    <td valign="baseline"><input type="submit" value="save" name="save" /></td>
                </tr>

                    




            </tbody>
        </table>
         </form>
    </article>

</section>
 
 <footer>  
<p>Lorem ipsum dolor sit amet...</p>
<p>Vivamus sed libero nec mauris pulvinar facilisis ut non sem...</p>
<p>Phasellus ligula massa, congue ac vulputate non, dignissim at augue...</p>
</footer>
</div>
</body>
</html>
